package com.geekaca.news.service.impl;

import com.geekaca.news.domain.Config;
import com.geekaca.news.mapper.ConfigMapper;
import com.geekaca.news.service.ConfigService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class ConfigServiceImpl implements ConfigService {
    @Autowired
    private ConfigMapper configMapper;

    @Override
    public List<Config> getAllConfigs() {
        return configMapper.getAllConfigs();
    }

    @Override
    public Map<String, String> getConfigMaps() {

        List<Config> allConfigs = configMapper.getAllConfigs();
        Map<String, String> configMap = new HashMap<>();
        allConfigs.forEach(config -> {
            configMap.put(config.getConfigName(),config.getConfigValue());
        });

        return configMap;
    }

    @Override
    public int updateWebSiteConfig(Config config) {
        return configMapper.updateConfig(config);
    }
}
